import barcode
from barcode import *
from barcode.writer import ImageWriter
from PIL import Image


def generate_barcode(data, filename):
    width = 0.5
    height = 20
    code = barcode.get('code128', data, writer=ImageWriter())
    options = {
        'module_width': width,
        'module_height': height,
    }
    code.save(filename, options=options)
    Image.open(filename+".png").show()

while True:
    code = input("输入编码：")
    generate_barcode(code, 'tmp')
